package com.doumuxie.dto;

import com.doumuxie.frame.ProductConsumeFrame;
import com.doumuxie.handler.ProductConsumeHandler;
import com.doumuxie.util.UUIDUtil;

import java.util.Random;

/**
 * @author doumuxie https://gitee.com/doumuxie/
 * @version 1.0
 * @date 2020/10/17 11:51
 * @description 生产者dto
 **/
public class ProductDto extends BaseDto {

    private Thread thread;

    public ProductDto(ProductConsumeFrame frame) {
        Random random = new Random();
        setId(UUIDUtil.getRandomId());
        setDelay(random.nextInt(1000) + 1000);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(getDelay());
                        GoodsDto dto = new GoodsDto();
//                        dto.setProductId(getId());
                        ProductConsumeHandler.insertGoods(dto);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        thread.start();
    }

    public Thread getThread() {
        return thread;
    }
}
